<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Module: vertx/event_bus</title>
    
    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">
    
    <h1 class="page-title">Module: vertx/event_bus</h1>
    
    



<section>
    
<header>
    <h2>
    vertx/event_bus
    </h2>
    
</header>  

<article>
    <div class="container-overview">
    
    
    
        
            <div class="description"><p>Represents a distributed lightweight event bus which can encompass
multiple vert.x instances.  It is very useful for otherwise isolated vert.x
application instances to communicate with each other. Messages sent over the
event bus are JSON objects.</p>

<p>The event bus implements a distributed publish / subscribe network.
Messages are sent to an address.  There can be multiple handlers registered
against that address.  Any handlers with a matching name will receive the
message irrespective of what vert.x application instance and what vert.x
instance they are located in.</p>

<p>All messages sent over the bus are transient. On event of failure of all
or part of the event bus messages may be lost. Applications should be coded
to cope with lost messages, e.g. by resending them, and making application
services idempotent.</p>

<p>The order of messages received by any specific handler from a specific
sender will match the order of messages sent from that sender.</p>

<p>When sending a message, a reply handler can be provided. If so, it will
be called when the reply from the receiver has been received.</p>

<p>This module can be used individually, or through the top-level
<a href="module-vertx.html"><code>vertx</code></a> module.</div>
        
        
        
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line91">line 91</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

        
        
            <h3>Example</h3>
            
        <p class="code-caption">Accessing the event bus</p>
    
    <pre class="prettyprint"><code>var vertx = require('vertx');

var eb1 = require('vertx/event_bus');
var eb2 = vertx.eventBus;

eb1.registerHandler('some-address', function(message) {
  print("Got a message! " + message);
}
eb2.publish('some-address', 'Hello world');</code></pre>

        
    
    </div>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        <h3 class="subsection-title">Methods</h3>
        
        <dl>
            
<dt>
    <h4 class="name" id="publish"><span class="type-signature">&lt;static> </span>publish<span class="signature">(address, message)</span><span class="type-signature"> &rarr; {<a href="event_bus.html">module:vertx/event_bus</a>}</span></h4>
    
    
</dt>
<dd>
    
    
    <div class="description">
        Publish a message on the event bus.
Message should be a JSON object It should have a property "address".
    </div>
    

    
    
    
    
    
        <h5>Parameters:</h5>
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>address</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last">The address to send the message to</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>message</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#Message">Message</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last">The message to send</td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line166">line 166</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    <h5>Returns:</h5>
    
            


<dl>
	<dt>
		Type
	</dt>
	<dd>
		
<span class="param-type"><a href="event_bus.html">module:vertx/event_bus</a></span>


	</dd>
</dl>

        
    
    
</dd>

        
            
<dt>
    <h4 class="name" id="registerHandler"><span class="type-signature">&lt;static> </span>registerHandler<span class="signature">(address, handler)</span><span class="type-signature"> &rarr; {<a href="event_bus.html">module:vertx/event_bus</a>}</span></h4>
    
    
</dt>
<dd>
    
    
    <div class="description">
        Register a handler.
    </div>
    

    
    
    
    
    
        <h5>Parameters:</h5>
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>address</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last">the address to register for. Any messages sent to
that address will be received by the handler. A single handler can be
registered against many addresses.</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>handler</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#MessageHandler">MessageHandler</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last">The handler</td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line122">line 122</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    <h5>Returns:</h5>
    
            
<div class="param-desc">
    the event bus
</div>



<dl>
	<dt>
		Type
	</dt>
	<dd>
		
<span class="param-type"><a href="event_bus.html">module:vertx/event_bus</a></span>


	</dd>
</dl>

        
    
    
</dd>

        
            
<dt>
    <h4 class="name" id="registerLocalHandler"><span class="type-signature">&lt;static> </span>registerLocalHandler<span class="signature">(address, handler)</span><span class="type-signature"> &rarr; {<a href="event_bus.html">module:vertx/event_bus</a>}</span></h4>
    
    
</dt>
<dd>
    
    
    <div class="description">
        Register a handler which won't be propageted acress the cluster.
    </div>
    

    
    
    
    
    
        <h5>Parameters:</h5>
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>address</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last">the address to register for. Any messages sent to
that address will be received by the handler. A single handler can be
registered against many addresses.</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>handler</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#MessageHandler">MessageHandler</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last">The handler</td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line107">line 107</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    <h5>Returns:</h5>
    
            
<div class="param-desc">
    The event bus
</div>



<dl>
	<dt>
		Type
	</dt>
	<dd>
		
<span class="param-type"><a href="event_bus.html">module:vertx/event_bus</a></span>


	</dd>
</dl>

        
    
    
</dd>

        
            
<dt>
    <h4 class="name" id="send"><span class="type-signature">&lt;static> </span>send<span class="signature">(address, message, <span class="optional">replyHandler</span>)</span><span class="type-signature"> &rarr; {<a href="event_bus.html">module:vertx/event_bus</a>}</span></h4>
    
    
</dt>
<dd>
    
    
    <div class="description">
        Sends a message on the event bus.
Message should be a JSON object It should have a property "address"
    </div>
    

    
    
    
    
    
        <h5>Parameters:</h5>
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		<th>Argument</th>
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>address</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="attributes">
                
                    
                
                    
                
                </td>
            
            
            
            
            <td class="description last">The address to send the message to</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>message</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#Message">Message</a></span>


            
            </td>
            
            
                <td class="attributes">
                
                    
                
                    
                
                </td>
            
            
            
            
            <td class="description last">The message to send</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>replyHandler</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#MessageHandler">MessageHandler</a></span>


            
            </td>
            
            
                <td class="attributes">
                
                    &lt;optional><br>
                
                    
                
                    
                
                </td>
            
            
            
            
            <td class="description last">called when the message receives a reply</td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line153">line 153</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    <h5>Returns:</h5>
    
            


<dl>
	<dt>
		Type
	</dt>
	<dd>
		
<span class="param-type"><a href="event_bus.html">module:vertx/event_bus</a></span>


	</dd>
</dl>

        
    
    
</dd>

        
            
<dt>
    <h4 class="name" id="unregisterHandler"><span class="type-signature">&lt;static> </span>unregisterHandler<span class="signature">(address, handler)</span><span class="type-signature"> &rarr; {<a href="event_bus.html">module:vertx/event_bus</a>}</span></h4>
    
    
</dt>
<dd>
    
    
    <div class="description">
        Unregisters a handler.
    </div>
    

    
    
    
    
    
        <h5>Parameters:</h5>
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>address</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last">The address the handler is registered to</td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>handler</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="global.html#MessageHandler">MessageHandler</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last">The handler to unregister</td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="event_bus.js.html">vertx/event_bus.js</a>, <a href="event_bus.js.html#line134">line 134</a>
    </li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    <h5>Returns:</h5>
    
            
<div class="param-desc">
    the event bus
</div>



<dl>
	<dt>
		Type
	</dt>
	<dd>
		
<span class="param-type"><a href="event_bus.html">module:vertx/event_bus</a></span>


	</dd>
</dl>

        
    
    
</dd>

        </dl>
    
    
    
    
    
</article>

</section>  




</div>

<nav>
    <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-vertx.html">vertx</a></li><li><a href="buffer.html">vertx/buffer</a></li><li><a href="console.html">vertx/console</a></li><li><a href="container.html">vertx/container</a></li><li><a href="event_bus.html">vertx/event_bus</a></li><li><a href="file_system.html">vertx/file_system</a></li><li><a href="http.html">vertx/http</a></li><li><a href="multi_map.html">vertx/multi_map</a></li><li><a href="net.html">vertx/net</a></li><li><a href="parse_tools.html">vertx/parse_tools</a></li><li><a href="pump.html">vertx/pump</a></li><li><a href="shared_data.html">vertx/shared_data</a></li><li><a href="sockjs.html">vertx/sockjs</a></li><li><a href="timer.html">vertx/timer</a></li></ul><h3>Externals</h3><ul><li><a href="InetSocketAddress.html">InetSocketAddress</a></li><li><a href="Buffer_.html">Buffer</a></li><li><a href="RecordParser.html">RecordParser</a></li><li><a href="SockJSSocket.html">SockJSSocket</a></li></ul><h3>Classes</h3><ul><li><a href="buffer-Buffer.html">Buffer</a></li><li><a href="file_system.AsyncFile.html">AsyncFile</a></li><li><a href="http.HttpClient.html">HttpClient</a></li><li><a href="http.HttpClientRequest.html">HttpClientRequest</a></li><li><a href="http.HttpClientResponse.html">HttpClientResponse</a></li><li><a href="http.HttpServer.html">HttpServer</a></li><li><a href="http.HttpServerFileUpload.html">HttpServerFileUpload</a></li><li><a href="http.HttpServerRequest.html">HttpServerRequest</a></li><li><a href="http.HttpServerResponse.html">HttpServerResponse</a></li><li><a href="http.RouteMatcher.html">RouteMatcher</a></li><li><a href="http.WebSocket.html">WebSocket</a></li><li><a href="multi_map-MultiMap.html">MultiMap</a></li><li><a href="net.NetClient.html">NetClient</a></li><li><a href="net.NetServer.html">NetServer</a></li><li><a href="net.NetSocket.html">NetSocket</a></li><li><a href="pump-Pump.html">Pump</a></li><li><a href="sockjs.SockJSServer.html">SockJSServer</a></li></ul><h3>Mixins</h3><ul><li><a href="ClientSSLSupport.html">ClientSSLSupport</a></li><li><a href="ReadStream.html">ReadStream</a></li><li><a href="ServerSSLSupport.html">ServerSSLSupport</a></li><li><a href="ServerTCPSupport.html">ServerTCPSupport</a></li><li><a href="SSLSupport.html">SSLSupport</a></li><li><a href="TCPSupport.html">TCPSupport</a></li><li><a href="WriteStream.html">WriteStream</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>

<br clear="both">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Wed Jul 17 2013 20:27:23 GMT+0100 (BST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>